#-*- coding : utf-8-*-
# coding:unicode_escape
import matplotlib as matplotlib

matplotlib.rcParams['axes.unicode_minus']=False
import seaborn as sns
sns.set(font= "Kaiti", style="ticks", font_scale=1.4)

import pandas as pd

from sklearn.impute import KNNImputer

oceanf2 = pd.read_excel("datas/data.xlsx")
oceandf = pd.read_excel("datas/data2.xlsx")
## 判断每个变量中是否存在缺失值
#data=pd.read_csv(io,encoding='unicode_escape')
print(pd.isna(oceandf).sum())

knnimp = KNNImputer(n_neighbors=5)
oceandfknn = knnimp.fit_transform(oceandf)

column = []
for index, row in oceandf.iteritems():
    column.append(index)

dataFrame = pd.DataFrame(oceandfknn, columns=column)
with pd.ExcelWriter('completed.xlsx') as writer: # 一个excel写入多页数据
     dataFrame.to_excel(writer, sheet_name='page1', float_format='%.6f')